<template>
  <el-dialog
    :title="!id ? '新增' : '修改'"
    :close-on-click-modal="false"
    @close="closeDialog()"
    :visible.sync="visible">
    <decode-component ref="addOrUpdateDecode" @refreshDecodeData="refreshDecodeData" @disDecodeVisible="disDecodeVisible"></decode-component>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import DecodeComponent from './configdecode-component'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        id: ''
      }
    },
    components: {
      DecodeComponent
    },
    methods: {
      init (id) {
        this.id = id
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
          this.$refs.addOrUpdateDecode.init(id)
        })
      },
      refreshDecodeData (decodeId) {
        this.$emit('refreshDataList')
      },
      disDecodeVisible () {
        this.visible = false
      },
      dataFormSubmit () {
        this.$refs.addOrUpdateDecode.dataFormSubmit()
      },
      //重置表单
      closeDialog() {
          this.id = ''
          this.$refs.addOrUpdateDecode.closeDialog()
      }
    }
  }
</script>
